<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { agentFormRules } from "./utils/rule";
import type { AdAgentFormProps } from "./utils/types";
import { platformOptions } from "./utils/config";

const props = withDefaults(defineProps<AdAgentFormProps>(), {
  formInline: () => ({
    platform: 1,
    name: ""
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="agentFormRules"
    label-width="100px"
    class="mx-auto max-w-lg"
  >
    <el-row :gutter="30">
      <re-col :value="24">
        <el-form-item label="平台" prop="platform">
          <el-radio-group v-model="newFormInline.platform">
            <el-radio
              v-for="option in platformOptions"
              :key="option.value"
              :label="option.value"
              size="large"
            >
              <el-tag
                :type="option.type"
                effect="plain"
                class="mx-1"
              >
                {{ option.label }}
              </el-tag>
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </re-col>

      <re-col :value="24">
        <el-form-item label="代理商名称" prop="name">
          <el-input
            v-model="newFormInline.name"
            clearable
            placeholder="请输入代理商名称"
            maxlength="100"
            show-word-limit
          />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>

<style lang="scss" scoped>
:deep(.el-radio) {
  margin-right: 20px;
  margin-bottom: 12px;
  
  .el-radio__label {
    padding-left: 8px;
  }
}

.el-tag {
  font-weight: normal;
}
</style> 